In [1]:
import graphlab
In [3]:
sf = graphlab.SFrame('people-example.csv')
In [4]:
sf #we can view first few lines of table
Out[4]:
In [5]:
sf.tail() # view end of the table
Out[5]:
In [7]:
# .show() visualizes any data structure in GraphLab Create
sf.show()
In [8]:
# If you want Canvas visualization to show up on this notebook,
# rather than popping up a new window, add this line:
graphlab.canvas.set_target('ipynb')
In [10]:
sf['age'].show(view='Categorical')
In [11]:
sf['Country']
Out[11]:
In [12]:
sf['age']
Out[12]:
Some simple columnar operations
In [13]:
sf['age'].mean()
Out[13]:
In [14]:
sf['age'].max()
Out[14]:
In [15]:
sf
Out[15]:
In [16]:
sf['Full Name'] = sf['First Name'] + ' ' + sf['Last Name']
In [17]:
sf
Out[17]:
In [18]:
sf['age'] * sf['age']
Out[18]:
In [19]:
sf['Country']
Out[19]:
In [20]:
sf['Country'].show()
In [21]:
def transform_country(country):
if country == 'USA':
return 'United States'
else:
return country
In [22]:
transform_country('Brazil')
Out[22]:
In [23]:
transform_country('Brasil')
Out[23]:
In [24]:
transform_country('USA')
Out[24]:
In [25]:
sf['Country'].apply(transform_country)
Out[25]:
In [26]:
sf['Country'] = sf['Country'].apply(transform_country)
In [27]:
sf
Out[27]:
In [ ]: